package com.jckj.core.vos;

import com.jckj.core.contants.SysContants;

/**
 * <p>
 *     ajax提交数据时，返回到前台的数据模型
 * </p>
 * @author liuzhiyuan
 * @date 2017-01-03
 *
 */
public class Result {

    /**
     * 返回代码
     */
    private int code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 正常返回,带数据
     * @param obj
     * @return
     */
    public static Result ok(Object obj){
        Result result = new Result();
        result.code = SysContants.RET_OK;
        result.data = obj;
        return result;
    }

    /**
     * 正常返回,带数据
     * @param message
     * @return
     */
    public static Result okWithMessage(String message){
        Result result = new Result();
        result.code = SysContants.RET_OK;
        result.message = message;
        return result;
    }

    /**
     * 正常返回，不带数据
     * @return
     */
    public static Result ok(){
        Result result = new Result();
        result.code = SysContants.RET_OK;
        return result;
    }

    /**
     * 参数错误，不带数据
     * @return
     */
    public static Result invalidParams(String message){
        Result result = new Result();
        result.code = SysContants.RET_INVALID_PARAM;
        result.message = message;
        return result;
    }

    /**
     * 参数错误，不带数据
     * @return
     */
    public static Result invalidParams(String message, Object obj){
        Result result = new Result();
        result.code = SysContants.RET_INVALID_PARAM;
        result.data = obj;
        return result;
    }

    /**
     * 资料未找到，不带数据
     * @return
     */
    public static Result notFound(String message){
        Result result = new Result();
        result.code = SysContants.RET_NOT_FOUNED;
        result.message = message;
        return result;
    }

    /**
     * 未授权，不带数据
     * @return
     */
    public static Result notAuth(String message){
        Result result = new Result();
        result.code = SysContants.RET_NOT_AUTH;
        result.message = message;
        return result;
    }

    /**
     * 执行出错，不带数据
     * @return
     */
    public static Result error(String message){
        Result result = new Result();
        result.code = SysContants.RET_EORROR;
        result.message = message;
        return result;
    }

    /**
     * 执行出错，带有数据
     * @return
     */
    public static Result error(String message, Object obj){
        Result result = new Result();
        result.code = SysContants.RET_EORROR;
        result.data = obj;
        return result;
    }

}